package com.rongke.web.heepay;


import com.rongke.web.heepay.util.HttpUtil;
import com.rongke.web.heepay.util.SmallTools;

/**
 * Created by Administrator on 2018/2/8.
 * 签约查询
 */
public class SignQuery {
    public static void main(String[] args){
        signQuery();
    }

    public static String signQuery() {
        String url = "https://open.heepay.com/signQuery.do";

        //请求参数
        //*注：此demo中的参数仅供测试使用，切勿上线使用，上线产品请使用自己的账号
        String merchantId = "101053";//商户号
        String merchantUserId = "123";//商户下面的用户ID
        String bankCardType = "-1";//银行卡类型，1=借记卡，2=信用卡，此参数不为1或2时代表全部查询
        String version = "2.0";//版本
        String productCode = "CP06";//产品编码
        String requestTime = SmallTools.getDate("yyyyMMddHHmmss");//请求时间，yyyyMMddHHmmss
        String sign = "";//签名
        String key = "331847e673623e7f0c4dfa8896caeabc";//商户密钥
        String deskey = key.substring(0,24);//商户密钥

        //拼接签名串
        String sign1 = "bankCardType="+bankCardType+
                "&merchantId="+merchantId+
                "&merchantUserId="+merchantUserId+
                "&productCode="+productCode+
                "&requestTime="+requestTime+
                "&version="+version+
                "&key="+key;

        System.out.println("签名参数："+sign1);
        //对签名参数进行MD5加密得到sign
        sign = SmallTools.MD5en(sign1);
        //拼接请求参数
        String parameter = "merchantId="+merchantId+
                "&merchantUserId="+merchantUserId+
                "&bankCardType="+bankCardType+
                "&version="+version+
                "&productCode="+productCode+
                "&requestTime="+requestTime+
                "&sign="+sign;
        System.out.println("请求参数："+parameter);
        String ret = HttpUtil.sendPost(url,parameter);
        System.out.println("返回的数据："+ret);
        Boolean isSign = SmallTools.checkSign(ret, key);
        System.out.println("验签结果："+isSign);
        if (isSign){
            return ret;
        }else {
            return "{\"retMsg\":\"返回数据验签失败\"}";
        }
    }
}
